/**
 * 交易流水管理初始化
 */
var Journal = {
    id: "JournalTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Journal.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '交易时间', field: 'create_time', visible: true, align: 'center', valign: 'middle'},
        {title: '门店', field: 'branch_name', visible: true, align: 'center', valign: 'middle'},
        {title: '会员', field: 'member_id', visible: true, align: 'center', valign: 'middle'},
        {title: '原价', field: 'origin_amount', visible: true, align: 'center', valign: 'middle'},
        {title: '优惠后金额', field: 'discount_amount', visible: true, align: 'center', valign: 'middle'},
        {title: '预充值扣费', field: 'balance_cost', visible: true, align: 'center', valign: 'middle'},
        {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Journal.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Journal.seItem = selected[0];
        return true;
    }
};


/**
 * 打开查看交易流水详情
 */
Journal.openJournalDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '交易流水详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/journal/journal_update/' + Journal.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 查询交易流水列表
 */
Journal.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Journal.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Journal.initColumn();
    var table = new BSTable(Journal.id, "/journal/list", defaultColunms);
    table.setPaginationType("server");
    // table.setQueryParams(Journal.formParams());
    Journal.table = table.init();

});
